package com.our.biz;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.our.dao.RewardTypeMapper;
import com.our.model.RewardType;
import com.our.model.Rewards;
import com.our.model.Users;
import com.our.util.BusinessException;

/**
 * @author hzp
 *
 */
@Service
public class RewardTypeBiz {
	@Resource
	private RewardTypeMapper dao;
	
	public List<RewardType> findAll() throws BusinessException{
		try {
			return dao.selectAll();
		} catch (Exception e) {
			throw new BusinessException("E0401B05");
		}
	}
	public RewardType findById(int typeId) throws BusinessException {
		try {
			return dao.selectByPrimaryKey(typeId);
		} catch (Exception e) {
			throw new BusinessException("E0401B04");
		}
	}
	public void update(RewardType reType) throws BusinessException {
		try {
			
			dao.updateByPrimaryKey(reType);
			
		} catch (Exception e) {
			throw new BusinessException("E0401B03");
		}
	}
	public void deleteById(int typeId) throws BusinessException {
		try {
			dao.deleteByPrimaryKey(typeId);
		} catch (Exception e) {
			throw new BusinessException("E0401B02");
		}
	}
	public void save(RewardType reType) throws BusinessException {
		try {
			dao.insert(reType);
		} catch (Exception e) {
			throw new BusinessException("E0401B01");
		}
	}
	public int countReward(int userId) throws BusinessException {
		try {
			return dao.countTypeId(userId);
		} catch (Exception e) {
			throw new BusinessException("E0401B06");
		}
	}
	public List<RewardType> findByUserId(int userId) throws BusinessException{
		try {
			return dao.selectByUserId(userId);
		} catch (Exception e) {
			throw new BusinessException("E0401B07");
		}
	}
	public int countNum(int userId,int rewardId,int typeState) throws BusinessException {
		try {
			return dao.countNum(userId, rewardId, typeState);
		} catch (Exception e) {
			throw new BusinessException("E0401B08");
		}
	}
	public List<RewardType> findByUserIdAndRewardId(Users user, Rewards reward) throws BusinessException {
		try {
			return dao.selectByUserIdAndRewardId(user,reward);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E0401B09");
		}
	}
	public List<RewardType> findByUserIdAndRewardId1(int userId, int rewardId)throws BusinessException {
		try {
			return dao.selectByUserIdAndRewardId1(userId,rewardId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E0401B09");
	}
}
}